import Vue from 'vue'
import Router from 'vue-router'
import  login from './components/login'
import  home from './components/home'
import  welecome from './components/welecome'
import  users from './components/users'
import  Character from './components/Character'
import  rights from './components/rights'
import  cate from './components/cate'
import  params from './components/Params'
import  goodsList from './components/list'
import  Add from './components/Add'
import  Order from './components/Order'
import  Report from './components/Report'

Vue.use(Router)
 
 const routes = [
   {
     path:'/',
     redirect:'/login'
   },
   {
    path:'/login',
    component:login
   },
   {
     path:'/home',
     component:home,
     children:[
       {
             path:'/',
             redirect:'/welecome'
       },
       {
       path:'/welecome',
       component:welecome
     },
     {
       path:'/users',
       component:users
     },
     {
       path:'/roles',
       component:Character
     },
     {
       path:'/rights',
       component:rights
     },
     {
       path:'/categories',
       component:cate
     },{
       path:'/params',
       component:params
     },
     {
       path:'/goods',
       component:goodsList,
     },
     {
          path:'/goods/add',
          component:Add
     },
     {
          path:'/orders',
          component:Order
     },
     {
          path:'/reports',
          component:Report
     }
     ]
   }
 ]
 const router = new Router({
 routes
})
router.beforeEach((to,from,next)=>{
  if(to.path==='/login') return next()
  const tokenstr = window.sessionStorage.getItem('token');
  // tokenstr?next('/login'):next()
  if(!tokenstr)return next('/login')
  next()
})
export default router
